var util = require('../../utils/util.js');
const md = require('../../utils/md5.js');
const app = getApp();
const post = require('../../utils/post.js');
Page({

  data: {
    search: 0
  },
  onLoad: function (options) {
    // console.log(options);
    var that = this;
    let province = options.province;
    let city = options.city;
    let area = options.area;
    that.setData({
      province:province,
      city:city,
      area:area
    })
    that.chushi();
  },
  searchbank: function () {
    var that = this;
    // 获取成员信息
    var datas = {};
    if (that.data.key == '') {
      that.chushi();
      that.setData({
        search: 0
      })
      return;
    }
    datas.where = "RegionName like '%" + that.data.key + "%' and RegionType=5 and RegionCode like '"+that.data.regcode+"%'";
    console.log(datas.where);
    var datacall = function (res) {
      console.log(res)
      if (res.data.data.length != 0) {
        that.setData({
          hotinfo: res.data.data,
          search:1
        })
      }
    }
    var res2 = post.getdata("/BO/BA_Region/Query", datas, datacall);
  },
  getkey: function (e) {
    this.setData({
      key: e.detail.value
    })
  },
  chushi: function () {
    var that = this;
    var datas = {};
    datas.where = '';
    if (that.data.area=='no'){
      datas.where = "RegionName = " + that.data.city + " and RegionType = 3";
    }else{
      datas.where = "RegionName = " + that.data.area + " and RegionType = 4";
    }
    var datacall = function (res) {
      console.log(res);
      if (res.data.data.length != 0) {
        let regioncode = res.data.data[0].RegionCode;
        that.hot(regioncode);
      }
    }
    var res2 = post.getdata("/BO/BA_Region/Query", datas, datacall);
  },
  hot: function (regcode) {
    var that = this;
    var datas = {};
    datas.where = "RegionCode like '" + regcode+"%' and RegionType = 5";
    var datacall = function (res) {
      console.log(res);
      if (res.data.data.length != 0) {
        that.setData({
          allinfo: res.data.data,
          regcode:regcode
        })
      }
    }
    var res2 = post.getdata("/BO/BA_Region/Query", datas, datacall);
  },
  pinyinpaixu: function (arr) {
    if (!String.prototype.localeCompare)
      return null;

    var letters = "*abcdefghjklmnopqrstwxyz".split('');
    var zh = "阿八嚓哒妸发旮哈讥咔垃痳拏噢妑七呥扨它穵夕丫帀".split('');

    var segs = [];
    var curr;
    letters.forEach(function (item, i) {
      curr = { letter: item, data: [] };
      arr.forEach(function (item2) {
        if ((!zh[i - 1] || zh[i - 1].localeCompare(item2) <= 0) && item2.localeCompare(zh[i]) == -1) {
          curr.data.push(item2);
        }
      });
      if (curr.data.length) {
        segs.push(curr);
        curr.data.sort(function (a, b) {
          return a.localeCompare(b);
        });
      }
    });
    return segs;
  },
  choosebank: function (e) {
    var that = this;
    var regionname = e.currentTarget.dataset.bank;
    wx.setStorageSync('regionname', regionname);
    wx.navigateBack({
      delta: 1
    })
  }
})